package cn.itrip.trade.controller;

import cn.itrip.beans.pojo.ItripHotelOrder;
import cn.itrip.trade.service.ItripOrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

@Controller
@RequestMapping("/api")
public class AliPaymentController {
    @Resource
    private ItripOrderService itripOrderService;

    @RequestMapping(value = "/prepay/{orderNo}", method = RequestMethod.GET)
    public String prePay(@PathVariable String orderNo, ModelMap model) throws Exception{
        try {
            ItripHotelOrder order = itripOrderService.getItripHotelOrderByOrderNo(orderNo);
            if(order == null){
                return "notfound";
            }
            model.addAttribute("hotelName", order.getHotelName());
            model.addAttribute("roomId", order.getRoomId());
            model.addAttribute("count", order.getCount());
            model.addAttribute("payAmount", order.getPayAmount());
            return "pay";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }
}
